{include file="common/mainHead"/}
<link rel="stylesheet" href="__ADMIN__/spectrum/spectrum.css">
<script>
    var ADMIN = '__ADMIN__';
    var UPURL = "{:url('UpFiles/upImages')}";
    var PUBLIC = "__PUBLIC__";
    var imgClassName,fileClassName;
</script>
{include file="common/mainFoot"/}
<script src="__STATIC__/ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="__STATIC__/ueditor/ueditor.all.js" type="text/javascript"></script>
<div class="admin-main fadeInUp animated">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form" method="post" action="{if condition="ACTION_NAME=='add'"}{:url('insert')}{else /}{:url('update')}{/if}">
    {if condition="$info['id'] neq ''"}<input TYPE="hidden" name="id" value="{$info.id}">{/if}
        {volist name="fields" id="r"}
            {if condition="!empty($r['status'])"}
                <div class="layui-form-item">
                    <label class="layui-form-label">{$r.name}</label>
                    <div class="layui-input-4" id="box_{$r['field']}">
                        {$r,input($r['field'])|getform=$form,###}
                    </div>
                </div>
            {/if}
        {/volist}
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                {if condition="MODULE_NAME eq 'page'"}
                <a href="{:url('category/index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
                {else /}
                <!--1061415018{:url('index',['catid'=>input('catid')])}-->
                <a href="{$lasturl}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
                {/if}
            </div>
        </div>
    </form>
</div>
<link rel="stylesheet" href="__ADMIN__/zyupload/skins/zyupload-1.0.0.min.css " type="text/css">
<script type="text/javascript" src="__ADMIN__/zyupload/zyupload.basic-1.0.0.min.js"></script>
<script src='__ADMIN__/spectrum/spectrum.js'></script>
<script src='__ADMIN__/js/edit.js'></script>
<script>
    var thumb,pic,file;
    {if condition="ACTION_NAME=='add'"}
    var url= "{:url('insert')}";
    {else /}
        var url= "{:url('update')}";
    {/if}
    layui.use(['form', 'layer','upload','layedit','laydate'], function () {
        var form = layui.form(), layer = layui.layer, upload = layui.upload,layedit = layui.layedit,laydate = layui.laydate;
        layedit.set({
            uploadImage: {
                url: '{:url("UpFiles/editUpload")}',
                type: 'post'
            }
        });
        var layeCon = layedit.build('content');
        upload({
            elem:'.thumb',
            url: '{:url("upFiles/upload")}',
            title: '上传缩略图',
            ext: 'jpg|png|gif', //那么，就只会支持这三种格式的上传。注意是用|分割。
            success: function(res, input){
                cltThumb.src = "__PUBLIC__"+res.url;
                thumb = res.url;
                if(res.code==0){
                    alert('上传图片大于300k');
                    window.location.reload();
                }
            }
        });
        form.on('submit(submit)', function (data) {
            // 提交到方法 默认为本身
            data.field.thumb = thumb;
            data.field.file = file;
            if($('#editType').val()=='0'){
                data.field.content = layedit.getContent(layeCon);
            }
            $.post(url, data.field, function (res) {
                if (res.code > 0) {
                    layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                        location.href = res.url;
                    });
                } else {
                    layer.msg(res.msg, {time: 1800, icon: 2});
                }
            });
        });
        form.verify({
            defaul:function(value,item){
                var minlength = $(item).attr('data-min');
                var maxlength = $(item).attr('data-max');
                var title = $(item).attr('title');
                var errormsg = $(item).attr('data-errormsg');
                var required = $(item).attr('data-required');
                if(maxlength>0 && errormsg){
                    if(value.length > maxlength || value.length<minlength) {
                        return errormsg;
                    }
                }
                if(required==1 && $.trim(value)==''){
                    return title+'不能为空';
                }
            },
            cn_username: function(value,item) {
                var title = $(item).attr('title');
                var regex=/^([\u4e00-\u9fa5]|[\w])+$/;
                if(!value.match(regex)) {
                    return title+'只包含中文数字英文字母和下划线！';
                }
            },
            chinese: function(value,item) {
                var title = $(item).attr('title');
                var regex=/^[\u4e00-\u9fa5]+$/;
                if(!value.match(regex)) {
                    return title+'只包含中文字符！';
                }
            }
        });
    });

    $('body').on('click','.jdImg',function(){
        var url = $(this).attr('data-url');
        var thispic = $(this);
        $.post("{:url('delImg')}",{'url':url},function(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6}, function (index) {
                    layer.close(index);
                    thispic.parent('.imgBox').remove();
                });
                return false;
            }else{
                layer.msg(data.msg, {icon: 5}, function(index){
                    layer.close(index);
                });
                return false;
            }
        })
    });
    $('.dImg').click(function(){
        var thispic = $(this);
        $(this).parent().find('.pics').removeClass('pics');
        var url = $(this).attr('data-url');
        var picurl = '';
        $(".pics").each(function(){
            picurl+= $(this).val()+'||:';
        });
        $.post("{:url('delImg')}",{'url':url,'picurl':picurl,'id':"{:input('id')}"},function(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6}, function (index) {
                    layer.close(index);
                    thispic.parent('.imgBox').remove();
                });
                return false;
            }else{
                layer.msg(data.msg, {icon: 5}, function(index){
                    layer.close(index);
                });
                return false;
            }
        });
    })
</script>
